<?php
/**
 * Created by PhpStorm.
 * User: l
 * Date: 2018/10/24
 * Time: 17:05
 */
namespace app\models;
use yii\db\ActiveRecord;

class Order_order extends ActiveRecord {

    public function getDynamicGift($dynamic_id,$limit,$offset){
        $post = Order_order::find()->where(['order_order.target_dynamic_id' => $dynamic_id]);

        $count = $post->count();
        $result = $post->JoinWith('user')->orderBy('order_order.order_id DESC')->limit($limit)->offset($offset)->asArray()->all();

        return ['total'=>$count, 'rows'=>$result];
    }

    //关联用户表 获取用户信息
    public function getUser()
    {
        //同样第一个参数指定关联的子表模型类名
        //第二个参数第一个是字表的 第二个是主表的
        return $this->hasOne(User_user::className(), ['user_id' => 'user_id']);
    }
}